//
//  HLEBaseResponse.m
//  HLENetwork_Example
//
//  Created by hle1879 on 2020/9/29.
//  Copyright © 2020 13434436448@163.com. All rights reserved.
//

#import "HLEBaseResponse.h"

@implementation HLEBaseResponse

- (instancetype)initWithResponse:(NSURLResponse * _Nullable)response responseObject:(id _Nullable)responseObject error:(NSError * _Nullable)error{
    self = [super init];
    if (self) {
        _success = !error;
        _response = response;
        _responseObject = responseObject;
        _error = error;
    }
    return self;
}

- (void)encodeWithCoder:(nonnull NSCoder *)coder {
    [coder encodeBool:_success forKey:@"success"];
    [coder encodeObject:_response forKey:@"response"];
    [coder encodeObject:_responseObject forKey:@"responseObject"];
    [coder encodeObject:_error forKey:@"error"];
}

- (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder {
    if (self = [super init]) {
        _success = [coder decodeBoolForKey:@"success"];
        _response = [coder decodeObjectForKey:@"response"];
        _responseObject = [coder decodeObjectForKey:@"responseObject"];
        _error = [coder decodeObjectForKey:@"error"];
    }
    return self;
}

@end
